|
1
|
|
|
import * as path from 'path'; |
|
2
|
|
|
import * as passport from 'passport'; |
|
3
|
|
|
import * as pg from 'pg'; |
|
4
|
|
|
import { NestFactory } from '@nestjs/core'; |
|
5
|
|
|
import { ValidationPipe } from '@nestjs/common'; |
|
6
|
|
|
import * as helmet from 'helmet'; |
|
7
|
|
|
import * as session from 'express-session'; |
|
8
|
|
|
import * as cookieParser from 'cookie-parser'; |
|
9
|
|
|
import * as connectPgSimple from 'connect-pg-simple'; |
|
10
|
|
|
import { NestExpressApplication } from '@nestjs/platform-express'; |
|
11
|
|
|
import { AppModule } from './app.module'; |
|
12
|
|
|
import { ITemplates } from './Infrastructure/Templates/ITemplates'; |
|
13
|
|
|
|
|
14
|
|
|
async function bootstrap() { |
|
15
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule); |
|
16
|
|
|
|
|
17
|
|
|
const sessionPgPool = new pg.Pool({ |
|
18
|
|
|
host: process.env.DATABASE_HOST, |
|
19
|
|
|
port: +process.env.DATABASE_PORT, |
|
20
|
|
|
user: process.env.DATABASE_USERNAME, |
|
21
|
|
|
password: process.env.DATABASE_PASSWORD, |
|
22
|
|
|
database: process.env.DATABASE_NAME |
|
23
|
|
|
}); |
|
24
|
|
|
|
|
25
|
|
|
app.use(helmet()); |
|
26
|
|
|
app.use(cookieParser()); |
|
27
|
|
|
app.useGlobalPipes( |
|
28
|
|
|
new ValidationPipe({ |
|
29
|
|
|
transform: true, |
|
30
|
|
|
transformOptions: { enableImplicitConversion: true } |
|
31
|
|
|
}) |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
app.use( |
|
35
|
|
|
session({ |
|
36
|
|
|
secret: 'my-secret', |
|
37
|
|
|
resave: false, |
|
38
|
|
|
saveUninitialized: false, |
|
39
|
|
|
store: new (connectPgSimple(session))({ |
|
40
|
|
|
pool: sessionPgPool, |
|
41
|
|
|
createTableIfMissing: true |
|
42
|
|
|
}) |
|
43
|
|
|
}), |
|
44
|
|
|
passport.session() |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
const assetsDir = path.join(__dirname, '..', 'public'); |
|
48
|
|
|
app.useStaticAssets(assetsDir, { prefix: '/public' }); |
|
49
|
|
|
|
|
50
|
|
|
const viewsDir = path.join(__dirname, '..', 'templates'); |
|
51
|
|
|
app.setBaseViewsDir(viewsDir); |
|
52
|
|
|
|
|
53
|
|
|
const templates: ITemplates = app.get('ITemplates'); |
|
54
|
|
|
templates.registerViewEngine(app, '/public'); |
|
55
|
|
|
|
|
56
|
|
|
await app.listen(3000, '0.0.0.0'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
bootstrap(); |
|
60
|
|
|
|